package com.xb;

import com.xb.Entity.examStudent;
import com.xb.util.dbUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * PreparedStatement小作业
 */
public class PreparedStatementHomeWork02 {
    //练习题1：从控制台向数据库的表customers中插入一条数据，表结构如下
    public static void main(String[] args) throws ParseException {
       while (true){
           Scanner scanner = new Scanner(System.in);
           System.out.println("请选择您要输入的类型：\n a:准考证号 \n b:身份证号 \n c:删除学生信息");
           String next = scanner.next();
           switch (next){
               case "a":
                   Scanner scanner01 = new Scanner(System.in);
                   System.out.println("请输入准考证号：");
                   String ExamCard = scanner01.next();
                   System.out.println("===========查询结果==========");
                   String sql = "select FlowID flowID,Type type,IDCard IdCard,ExamCard examCard,StudentName studentName," +
                           "Location location,Grade garde FROM examstudent where ExamCard = ?";
                   examStudent examStudent = dbUtil.selectGetData02(sql, examStudent.class, ExamCard);
                   if (examStudent!=null){
                       System.out.println(examStudent);
                       continue;
                   }else {
                       System.out.println("查无此人");
                       break;
                   }
               case "b":
                   Scanner scanner02 = new Scanner(System.in);
                   System.out.println("请输入身份证：");
                   String idCard = scanner02.next();
                   System.out.println("===========查询结果==========");
                   String sqlById = "select FlowID flowID,Type type,IDCard IdCard,ExamCard examCard,StudentName studentName," +
                           "Location location,Grade garde FROM examstudent where IDCard = ?";
                   examStudent stu = dbUtil.selectGetData02(sqlById, examStudent.class, idCard);
                   if (stu!=null){
                       System.out.println(stu);
                       continue;
                   }else {
                       System.out.println("查无此人");
                       break;
                   }
               case "c":
                   Scanner deleteScanner = new Scanner(System.in);
                   System.out.println("请输入你要删除的学生准考证号：");
                   String stuId = deleteScanner.next();
                   String delteSql = "delete from examstudent where ExamCard =?";
                   dbUtil.DclSql02(delteSql,stuId);
                   System.out.println("删除成功~");
               default:
                   System.out.println("您输入的信息有误！");
                   break;

           }

       }
    }
}
